package com.itheima.collectiondemo;

import java.util.ArrayList;
import java.util.Iterator;

/**
 * @Author 王加鑫
 * @Date 2021/5/13 11:32
 * @Version 1.0
 */
public class IteratorDemo03 {
    public static void main(String[] args) {
        ArrayList<Student> list = new ArrayList<>();
        Student student1 = new Student("小皮同学",23);
        Student student2 = new Student("小路同学",23);
        Student student3 = new Student("小贾同学",23);
        list.add(student1);
        list.add(student2);
        list.add(student3);

        for (Student student : list) {
            System.out.println(student);
        }

        System.out.println("==============================");

        Iterator<Student> iterator = list.iterator();
        while (iterator.hasNext()){
            System.out.println(iterator.next());
        }

        System.out.println("==============================");

        list.forEach( student -> System.out.println(student));
    }
}
